package com.xuecheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.mapper.CourseTeacherMapper;
import com.xuecheng.model.po.CourseTeacher;
import com.xuecheng.service.CourseTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 小班哥
 * @version 1.0
 * @date 2023/3/19 16:11
 * @description 课程对应师资信息
 */

@Service
public class CourseTeacherServiceImpl implements CourseTeacherService {

    @Autowired
    private CourseTeacherMapper courseTeacherMapper;

    /**
     * 查询课程先关教师
     * @param courseID
     * @return
     */
    @Override
    public List<CourseTeacher> courseTeacherInfo(long courseID) {
        LambdaQueryWrapper<CourseTeacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CourseTeacher::getCourseId , courseID);
        List<CourseTeacher> courseTeachers = courseTeacherMapper.selectList(queryWrapper);
        return courseTeachers;
    }

    /**
     * 添加课程相关教师
     * @param courseTeacher
     */
    @Override
    public void AddTeacher(CourseTeacher courseTeacher) {
        CourseTeacher selectIsNot = courseTeacherMapper.selectById(courseTeacher.getId());
        if (selectIsNot != null){
            courseTeacherMapper.updateById(courseTeacher);
        }else {
            courseTeacher.setCreateDate(LocalDateTime.now());
            courseTeacherMapper.insert(courseTeacher);
        }
    }

    /**
     * 删除课程对应的讲师
     * @param teacherID
     */
    @Override
    public void DeleteTeacherInfo(long teacherID , long id) {
        LambdaQueryWrapper<CourseTeacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(teacherID != 0 ,CourseTeacher::getCourseId , teacherID);
        queryWrapper.eq(0 != id , CourseTeacher::getId , id);
        int delete = courseTeacherMapper.delete(queryWrapper);
    }
}
